package com.test.controller;

import com.test.po.*;
import com.test.service.CartService;
import com.test.service.ProductsService;
import com.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class MenuController {
    @Autowired
    private CartService cartService;
    @Autowired
    private  ProductsService productsService;
    @Autowired
    private UserService userService;


    @RequestMapping("/forindex.do")

    public String forindex(){

        return "index";
    }

    @RequestMapping("/forcart.do")
    public String forcart( Integer uid,ModelMap map){
//        HttpSession session = request.getSession();
//        int uid = (int) request.getAttribute("uid");
        List<Cart> cartList = cartService.selectByUid(uid);
        map.addAttribute("cartList", cartList);
        return "mycart";
    }
    @RequestMapping("/forpadd.do")

    public String forpadd(){

        return "padd";
    }
    @RequestMapping("/forpmodify.do")

    public String forpmodify(){

        return "pmodify";
    }

    @RequestMapping("/forplist.do")

    public String forplist(ModelMap map){
        List<Products> productsList = productsService.selectByExample(new ProductsExample());

        map.addAttribute("productsList",productsList);

        return "plist";
    }
    @RequestMapping("/foradindex.do")

    public String foradindex(){

        return "adindex";
    }
    @RequestMapping("/foruadd.do")

    public String foruadd(){

        return "uadd";
    }
    @RequestMapping("/forulist.do")

    public String forulist(ModelMap map){
        List<User> userList = userService.selectByExample(new UserExample());

        map.addAttribute("userList",userList);

        return "ulist";
    }
    @RequestMapping("/forcount.do")

    public String forcount(){

        return "count";
    }

}
